//
//  OneVC.m
//  timelyRain
//
//  Created by Jiafei Wei on 16/8/5.
//  Copyright © 2016年 Jiafei Wei. All rights reserved.
//

#import "OneVC.h"
#import "TwoVC.h"
#import "DbManage.h"
#import "BindTool.h"
#import "ContactPersonInfo.h"
@interface OneVC ()
- (IBAction)setting:(id)sender;
- (IBAction)notice:(id)sender;
@property (weak, nonatomic) IBOutlet UIImageView *bigImageV;
- (IBAction)openWifi:(id)sender;
- (IBAction)openHotPoint:(id)sender;
@property (weak, nonatomic) IBOutlet UIImageView *head;

@end

@implementation OneVC

- (void)viewDidLoad {
    [super viewDidLoad];
    //[self doAnim:_bigImageV];
    [self setHeadPic];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateHeadPic:) name:@"update_url" object:nil];
}
-(void)updateHeadPic:(NSNotification*)sender{
   NSDictionary *dataUser = sender.userInfo;
    NSString *url =[dataUser objectForKey:@"data"];
    [_head sd_setImageWithURL:[NSURL URLWithString:url]];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    [self doAnim:_bigImageV];
}
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:YES];
    [self stopAnim:_bigImageV];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

-(void)stopAnim:(UIView *)view{
    [view.layer removeAllAnimations];
}

-(void)doAnim:(UIView *)view{
    CAKeyframeAnimation *rotationAni = [CAKeyframeAnimation animation];
    rotationAni.keyPath = @"transform.rotation";
    rotationAni.values = @[@0,@(M_PI * 2),@(M_PI * 4)];
    rotationAni.duration = 3;
    rotationAni.repeatCount =MAXFLOAT;
    [view.layer addAnimation:rotationAni forKey:nil];
}
- (IBAction)setting:(id)sender {
    TwoVC *setting =[[TwoVC alloc]init];
    [self.navigationController pushViewController:setting animated:YES];
}

- (IBAction)notice:(id)sender {
    
}
- (IBAction)openWifi:(id)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];//只能到设置界面
}
- (IBAction)openHotPoint:(id)sender {
    
}
-(void)setHeadPic{
    NSMutableArray *array =[[DbManage shareDbManage]queryPersonInfoByUserId:[BindTool share].bindInfo.phone_number];
    if (array.count!=0) {
        ContactPersonInfo *info = [array objectAtIndex:0];
        _head.layer.masksToBounds=YES;
        _head.layer.cornerRadius=_head.frame.size.height/2;
        [_head sd_setImageWithURL:[NSURL URLWithString:info.head_pic]];
    }
}
@end
